#define _CRT_SECURE_NO_WARNINGS 1
class Solution
{
    vector<int> path;
    vector<vector<int>> ret;
public:
    vector<vector<int>> subsets(vector<int>& nums)
    {

        dfs(nums, 0);
        return ret;
    }
    void dfs(vector<int>& nums, int pos)
    {
        ret.push_back(path);
        if (pos == nums.size()) return;

        for (int i = pos; i < nums.size(); i++)
        {
            path.push_back(nums[i]);
            dfs(nums, i + 1);
            path.pop_back();
        }
    }
};
class Solution
{
    vector<bool> check;
    vector<vector<int>> ret;
    vector<int> tmp;
    int n;
public:
    vector<vector<int>> permute(vector<int>& nums)
    {
        n = nums.size();
        check = vector<bool>(n);
        dfs(nums);
        return ret;
    }
    void dfs(vector<int>& nums)
    {
        if (tmp.size() == n)
        {
            ret.push_back(tmp);
            return;
        }
        for (int i = 0; i < n; i++)
        {
            if (!check[i])
            {
                tmp.push_back(nums[i]);
                check[i] = true;
                dfs(nums);
                tmp.pop_back();
                check[i] = false;
            }
        }
    }
};